package com.zmn.oms.dubbo.impl.zmn.master.discount;

import com.alibaba.fastjson.JSON;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.manager.redis.lock.DistributedLock;
import com.zmn.manager.redis.lock.DistributedLockUtils;
import com.zmn.oms.common.constant.LockConsts;
import com.zmn.oms.common.constant.OrderStatusConsts;
import com.zmn.oms.common.constant.TriggerAmountChangeEnum;
import com.zmn.oms.common.dto.OmsBaseOperator;
import com.zmn.oms.common.dto.OmsOperator;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.dubbo.dto.common.work.discount.WorkTimesCardInfoDRO;
import com.zmn.oms.dubbo.interfaces.zmn.master.discount.OrderDiscountListRemoterService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.bo.orderamount.OrderAmountCalcBO;
import com.zmn.oms.model.bo.orderamount.ReCalcOrderAmountDIO;
import com.zmn.oms.model.bo.work.discount.WorkTimesCardInfoBO;
import com.zmn.oms.model.entity.work.OrderWork;
import com.zmn.oms.zmn.normal.business.interfaces.discount.ZsNormalOrderDiscountBService;
import com.zmn.pay.common.constant.PayConsts;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Objects;

/**
 * @author sunlife
 * @date:2022/3/9 11:51 上午
 * description:
 */
@Slf4j
@Service(loadbalance = "roundrobin", timeout = 15000, retries = 2, version = DubboConsts.INTERFACE_VERSION)
public class OrderDiscountListRemoterServiceImpl implements OrderDiscountListRemoterService {

    @Autowired
    ZsNormalOrderDiscountBService zsNormalOrderDiscountBService;

    @Override
    public ResponseDTO<WorkTimesCardInfoDRO> getOrderTimesDiscountInfo(OmsOperator dio) {
        log.info("获取次卡使用信息：{}", JSON.toJSONString(dio));
        try {
            WorkTimesCardInfoBO workTimesCardInfoBO = zsNormalOrderDiscountBService.getOrderTimesDiscountInfo(dio.getOrderId(), dio.getWorkId());
            return ResponseDTO.success(BeanMapper.map(workTimesCardInfoBO, WorkTimesCardInfoDRO.class));
        } catch (OmsBaseException e) {
           log.error("获取订单权益卡信息失败", e);
           return ResponseDTO.fail(e.getCode(), e.getMessage());
        } catch (Exception e) {
            log.error("获取订单权益卡信息失败", e);
            return ResponseDTO.fail("获取订单权益卡信息失败");
        }


    }
}
